package 双指针;

import java.util.ArrayList;

/**
 * @author 帅小伙
 * @date 2021/12/26
 * @description
 */
public class Demo01JZ57 {

    ArrayList<Integer>res = new ArrayList<Integer>();
    public ArrayList<Integer> FindNumbersWithSum(int [] array, int sum) {
        int l = 0, r = array.length-1;
        while(l < r){
            int t = array[l] + array[r];
            if(t == sum ){
                res.add(array[l]);
                res.add(array[r]);
                break;
            }else if(t > sum){
                r--;
            }else{
                l++;
            }
        }
        return res;
    }
}
